"""
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    created by lei.chang on '24/05/2023'
    comment: 服务记录相关
"""
from sqlalchemy import func
from sqlalchemy.dialects.mysql import VARCHAR, INTEGER, BOOLEAN, FLOAT, DATETIME, TIMESTAMP, DATE

from project.core.base import CustomModel, CustomList, CustomDict
from project.core.base import Column


class FlowRecord(CustomModel):
    """ 服务记录表
    """
    __tablename__ = "flow_record"
    id = Column(INTEGER(unsigned=True), primary_key=True, autoincrement=True)
    code = Column(VARCHAR(30), unique=True, comment='服务记录编号')
    business_date = Column(DATE, comment='服务记录日期')
    flow_id = Column(INTEGER(unsigned=True), nullable=False, server_default='0', comment='服务流程id')
    flow_code = Column(VARCHAR(30), nullable=False, server_default='', comment='服务流程编号')
    organization_code = Column(VARCHAR(10), nullable=False, server_default='', comment='机构编号', is_displayed=False)
    status = Column(VARCHAR(20), nullable=False, server_default='init', comment='交互流程状态 init(待完成)/success(已完成)/cancel(已取消)')
    flow_process_id = Column(INTEGER(unsigned=True), nullable=False, server_default='0', comment='流程状态id')
    flow_process_name = Column(VARCHAR(50), nullable=False, server_default='init', comment='流程状态名称')
    dev_id = Column(VARCHAR(30), nullable=False, server_default='', comment='设备id')
    room_no = Column(VARCHAR(30), nullable=False, server_default='', comment='房间号')
    resource = Column(CustomDict(2000), nullable=False, server_default='', comment='上传图片、视频资料信息')
    submit = Column(CustomList(2000), nullable=False, server_default='', comment='组件提交的信息')
    reason = Column(VARCHAR(200), nullable=False, server_default='', comment='取消原因')
    is_deleted = Column(BOOLEAN, nullable=False, server_default='0', comment='是否删除 0: 未删除 1: 已删除', is_displayed=False)
    create_time = Column(DATETIME, nullable=False, server_default=func.now())
    update_time = Column(TIMESTAMP, nullable=False, server_default=func.now(), onupdate=func.now())


class FlowRecordDetail(CustomModel):
    """ 服务记录表
    """
    __tablename__ = "flow_record_detail"
    id = Column(INTEGER(unsigned=True), primary_key=True, autoincrement=True)
    flow_record_id = Column(INTEGER(unsigned=True), nullable=False, server_default='0', comment='服务记录id')
    flow_id = Column(INTEGER(unsigned=True), nullable=False, server_default='0', comment='服务流程id')
    flow_code = Column(VARCHAR(30), nullable=False, server_default='', comment='服务流程编号')
    node_id = Column(INTEGER(unsigned=True), nullable=False, server_default='0', comment='流程节点id')
    node_code = Column(VARCHAR(30), nullable=False, server_default='', comment='流程节点编号')
    node_type = Column(VARCHAR(30), nullable=False, server_default='', comment='节点类型')
    node_name = Column(VARCHAR(30), nullable=False, server_default='', comment='节点名称')
    group_title = Column(VARCHAR(30), nullable=False, server_default='', comment='分组名')
    title = Column(VARCHAR(30), nullable=False, server_default='', comment='项目名称')
    image = Column(VARCHAR(500), nullable=False, server_default='', comment='项目图片')
    count = Column(INTEGER(unsigned=True), nullable=True, comment='数量')
    price = Column(FLOAT, nullable=True, comment='单价')
    spec = Column(CustomList(2000), comment='规格信息 [{"title": xxx, "items": [xxx, xxx, xxx]}, {"title": xxx, "items": [xxx, xxx, xxx]}]')
    date = Column(VARCHAR(30), nullable=False, server_default='', comment='选择的日期 today(今日)/tomorrow(明日)/after_tomorrow(后日)/2025-03-14')

    time_duration = Column(VARCHAR(30), nullable=False, server_default='', comment='选择时长')

    create_time = Column(DATETIME, nullable=False, server_default=func.now(), is_displayed=False)
    update_time = Column(TIMESTAMP, nullable=False, server_default=func.now(), onupdate=func.now(), is_displayed=False)


class FlowRecordLog(CustomModel):
    """
    """
    __tablename__ = "flow_record_status_log"
    id = Column(INTEGER(unsigned=True), primary_key=True, autoincrement=True)
    flow_record_id = Column(INTEGER(unsigned=True), nullable=False, server_default='0', comment='服务记录id')
    flow_role_id = Column(INTEGER(unsigned=True), nullable=False, server_default='0', comment='流程角色id')
    flow_role_phone = Column(VARCHAR(20), nullable=False, server_default='', comment='联系电话')
    flow_process_id = Column(INTEGER(unsigned=True), nullable=False, server_default='0', comment='流程状态id')
    flow_process_name = Column(VARCHAR(50), nullable=False, server_default='', comment='流程状态名称')
    record_status = Column(VARCHAR(20), nullable=False, server_default='init', comment='服务记录状态 init(待完成)/success(已完成)/cancel(已取消)')
    is_sms_notified = Column(BOOLEAN, nullable=False, server_default='0', comment='是否已短信通知 0: 未通知 1: 已通知', is_displayed=False)
    is_tel_notified = Column(BOOLEAN, nullable=False, server_default='0', comment='是否已语音通知 0: 未通知 1: 已通知', is_displayed=False)
    create_time = Column(DATETIME, nullable=False, server_default=func.now())
    update_time = Column(TIMESTAMP, nullable=False, server_default=func.now(), onupdate=func.now())
